class Solution:
    def imageSmoother(self, img: list[list[int]]) -> list[list[int]]:
        col, line = len(img[0]), len(img)
        k = list()
        for i in range(line):
            avg = list()
            for j in range(col):
                a1 = max(0, i-1)
                a2 = min(i+1, line-1)
                b1 = max(0, j-1)
                b2 = min(j+1, col-1)
                g = 0
                for x in range(a1, a2+1):
                    for y in range(b1, b2+1):
                        g += img[x][y]
                g = int(g/((a2-a1+1)*(b2-b1+1)))
                avg.append(g)
            k.append(avg)
        return k
    
if __name__ == '__main__':
    s = Solution()
    print(s.imageSmoother([[1,1,1],[1,0,1],[1,1,1]]))